package com.jakx.controller.kafka;

import com.alibaba.fastjson.JSONObject;
import com.jakx.service.kafka.KafkaProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.util.Date;

@RestController
public class KafkaController {

    @Autowired
    private KafkaProducer kafkaProducer;

    @PostMapping("/upload")
    public void upload(MultipartFile file) throws Exception {
        System.out.println(file.getName());
        System.out.println(file.getOriginalFilename());
        System.out.println(file.getSize());
        String folder = "/test";

        File localFile = new File(folder, new Date().getTime()+".txt");

        file.transferTo(localFile);
    }

    @ResponseBody
    @RequestMapping(value = "/kafka", method = RequestMethod.GET, produces = "text/plain")
    public String test() {
//        kafkaProducer.sendMsg("hhh");
        return "success";
    }


    @RequestMapping("/kk1")
    public String login(String username, String password) {
        System.out.println(username);
        System.out.println(password);
       return "ttt";
    }
}
